import { Controller, Get, Post, Body, Patch, Param, Delete, Request, Query } from '@nestjs/common'
import { NoteService } from './note.service'
import { CreateNoteDto } from './dto/create-note.dto'
import { UpdateNoteDto } from './dto/update-note.dto'
import { CustomRequest } from 'src/type'

@Controller('note')
export class NoteController {
  constructor(private readonly noteService: NoteService) {}

  // 新增笔记
  @Post()
  create(@Body() createNoteDto: CreateNoteDto, @Request() req: CustomRequest) {
    return this.noteService.create(createNoteDto, req)
  }

  // 获取所有笔记
  @Get()
  findAll(@Request() req: CustomRequest, @Query() query: { pageNo: number; PageSize: number }) {
    return this.noteService.findAll(req, query)
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.noteService.findOne(+id)
  }

  // 修改笔记
  @Patch(':id')
  update(@Param('id') id: string, @Body() updateNoteDto: UpdateNoteDto) {
    return this.noteService.update(+id, updateNoteDto)
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.noteService.remove(+id)
  }
}
